package com.netease.course.homework.web.controller;

import com.netease.course.homework.meta.User;
import com.netease.course.homework.serivce.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.io.Writer;

/**
 * Created by yanfa on 2016/10/30.
 */
@Controller
public class UserController {

    @Autowired
    UserService userServiceImpl;

    @RequestMapping(value = "/hello")
    public void hello(Writer writer) throws IOException {
        for(User user : this.userServiceImpl.findAll())
            writer.write(user.getUserName());
    }

    @RequestMapping(value = "/user")
    public String findAll(ModelMap map){
        map.addAttribute("userList",this.userServiceImpl.findAll());

        return "user_list";
    }
}
